/*
 * @Author: Yuluo 568055454@qq.com
 * @Date: 2023年06月18日 06:40:17
 * @LastEditors: Yuluo 568055454@qq.com
 * @LastEditTime: 2023年06月24日 17:43:26
 * @FilePath: \Mood-Blog-System\back\models\Category.js
 * @Description:  Category表模型定义文件
 * Copyright (c) 2023 by Yuluo, All Rights Reserved. 
 */

const { mongoose } = require('../db');

const schema = mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        required: true,
        ref: 'User',
        autopopulate: true,
    },
    name: {
        type: String,
        required: true,
        unique: true,
        max: 20,
        min: 1,
        trim: true,
        index: true,
    },
    desc: {
        type: String,
        default: '',
        max: 100,
        trim: true,
    },
    status: { type: String, default: 'normal', enum: ['normal', 'disabled', 'deleted'] },
    deletedAt: { type: Date, default: null },
}, {
    timestamps: true,
});

schema.plugin(require('mongoose-autopopulate'));
schema.plugin(require('mongoose-unique-validator'));
module.exports = mongoose.model('Category', schema, 'category');
